#!/bin/bash

set -e

PHP_CMD=( php )

OUT_DIR="generated/"

function do_lemon() {
    local input="$1"
    local name=$(basename "${input}")
    (
        cd generated &&
        rm -f "${name}" &&
        cp ../"${input}" "${name}" &&
        ../lemon/lemon "${name}"
    )
}

mkdir -p generated

"${PHP_CMD[@]}" blog_generator/blog.php --input-file blog_channels.txt --output-dir "${OUT_DIR}"
do_lemon ncd/NCDValueParser_parse.y
